package com.yfore.jfinal.pdf.plugin;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


/**
 * 
 * @author farmer
 *
 */
public class IO {
	
	public static String readIO(InputStream in){
		StringBuffer s = new StringBuffer();
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new InputStreamReader(in));
			String line = null;
			while((line=reader.readLine()) != null){
				s.append(line);
				s.append("\n");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				if(reader != null){
					reader.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return s.toString();
	}
	
	
	/**
	 * 读取文件
	 * @param file
	 * @return
	 */
	public static String readFile(File file){
		try {
			return readIO(new FileInputStream(file));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		return "";
	}
	
	/**
	 * 读取文件
	 * @param file
	 * @return
	 */
	public static String readFile(String file) {
		return readFile(new File(file));
	}
	
	
}
